草庐IT

linux shell kill信号SIGKILL && KILL

全部标签

ruby-on-rails - 将散列收集到 OpenStruct 中创建 "table"条目

为什么这样(在Rails控制台中评估)[{:a=>:b}].collect{|x|OpenStruct.new(x)}.to_json在那里添加一个“表”记录?"[{\"table\":{\"a\":\"b\"}}]我只想要这个:"[{\"a\":\"b\"}]这是否意味着Rails的to_json方法以不同的方式处理OpenStruct?当我在irb中尝试时,它不存在:require'ostruct'[{:a=>:b}].collect{|x|OpenStruct.new(x)}.inspect 最佳答案 因为@tableisai

ruby - "too clever"的 Ruby 代码示例是什么?

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭9年前。Improvethisquestion我曾与一些程序员friend讨论过,他们说他们看到Ruby程序员(尤其是)编写了很多“太聪明”的代码。所以我想知道那会是什么样子?我指的是在直截了当的事情同样有效或更好的情况下不必要地使用晦涩的语言功能。知道这方面的任何好的Ruby示例吗?

ruby - 点击服务器错误 `<module:Templates>':未初始化常量 Tilt::CompileSite (NameError)

我正在尝试将我的sqlite3数据库迁移到postgresql,但我无法通过此错误。当我运行tapsserversqlite://db/development.sqlite3[user][password]我不断收到/Users/phillipjarrar/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/sinatra-1.0/lib/sinatra/base.rb:298:in:uninitializedconstantTilt::CompileSite(NameError) 最佳答案

ruby - bundler 的可执行文件 "bundle"与/usr/local/bin/bundle 冲突 覆盖可执行文件?

当我安装jekyllbundle并输入命令geminstalljekyllbundler时。终端弹出bundler的可执行文件“bundle”与/usr/local/bin/bundle冲突的消息覆盖可执行文件? 最佳答案 在我的例子中,我必须覆盖/usr/local/bin/bundle和/usr/local/bin/bundler才能成功安装bundler-1.16.6.否则,在运行jekyllnewwebsitedir时,会出现以下消息的错误。Bundler:ruby:Nosuchfileordirectory--/usr/l

ruby-on-rails - cucumber + capybara : Problem with a scenario that redirects the browser outside of my app

GivenIhavearailsappAndI'musingcucumberAndI'musingcapybaraAndIhaveanactionthatresultsinaredirect_to"http://some.other.domain.com/some_path"WhenItestthisactionThenthein-appportionofthetestworksfineButIseethiserror:Noroutematches"/some_path"with{:method=>:get}(ActionController::RoutingError)所以capyb

ruby-on-rails - "msvcrt-ruby18.dll was not found"与 ruby

当我尝试运行简单的rails命令时,例如:rails-h几秒钟后我收到一个弹出式错误消息:ruby.exe-UnableToLocateComponentThisapplicationhasfailedtostartbecausemsvcrt-ruby18.dllwasnotfound.Re-installingtheapplicationmayfixtheproblem.我在运行:WindowsXP(是的,我知道我应该尝试在Windows机器上使用ruby​​)。ruby1.9.1p378[i386-mingw32]。已将我所有的gem更新到最新版本(截至2010年7月14日)。有什

ruby - 如何递归地用 ""替换 ruby​​ 哈希中的所有 nil 值?

str=""hash=Hash.from_xml(str)#=>{"a"=>{"b"=>{"c"=>nil}}}如何将散列中的所有nil替换为"",以便散列变为:{"a"=>{"b"=>{"c"=>""}}} 最佳答案 这里是递归的方法,不改变原来的hash。代码defdenilize(h)h.each_with_object({}){|(k,v),g|g[k]=(Hash===v)?denilize(v):v.nil??'':v}end示例h={"a"=>{"b"=>{"c"=>nil}}}denilize(h)#=>{"a"=>

ruby-on-rails - 在预编译 Assets 上出现此错误:TypeError: couldn't digest ActiveSupport::StringInquirer

我是一个相对较新的Rails程序员,当我尝试预编译Assets(有时甚至运行服务器)时,我得到这个错误:TypeError:couldn'tdigestActiveSupport::StringInquirer/Users/Lucia/jruby/lib/ruby/gems/shared/gems/sprockets-3.5.2/lib/sprockets/digest_utils.rb:83:in`digest'/Users/Lucia/jruby/lib/ruby/gems/shared/gems/sprockets-3.5.2/lib/sprockets/loader.rb:55

ruby - 正则表达式 "empty range in char class error"

我的代码中有一个正则表达式,用于匹配url的模式并抛出错误:/^(http|https):\/\/([\w-]+\.)+[\w-]+([\w-.\/?%&=]*)?$/错误是“字符类错误中的空范围”。我发现原因在([\w-.\/?%&=]*)?部分。Ruby似乎将\w-.中的-识别为范围运算符,而不是文字-。给dash加上escape后问题解决。但原来的正则表达式在我同事的机器上运行良好。我们使用相同版本的osx、rails和ruby:Ruby版本是ruby1.9.3p194,rails是3.1.6,osx是10.7.5。在我们将代码部署到我们的Heroku服务器之后,一切都运行良好。

ruby - 如何让 rbenv 识别 '1.9.3-p***' Ruby 版本?

我正在尝试运行一些Ruby项目,并且该项目正在使用.ruby-version文件。该文件仅包含:1.9.3我安装了最新的Ruby1.9.3:$rbenvinstall1.9.3-p448然而,当我运行ruby--version时,我得到了rbenv:version'1.9.3'isnotinstalled为了修复这个错误,我列出了~/.rbenv/versions/并且它包含文件夹1.9.3-p448。我将该文件夹重命名为1.9.3并运行rbenvrehash。这解决了问题。看起来-p448部分(什么意思?补丁?)混淆了rbenv。如何在不手动重命名~/.rbenv中的文件夹的情况下使